<template>
  <div>
    <Button @click="doGetReq">发送getReq</Button>
    <p>{{msg}}</p>
  </div>
</template>

<script>
// import reqGlobal from '../api/reqGlobal'
import { testGet } from "../api/restSysApi/user";
import { testMockApi } from "../api/restSysApi/user";

export default {
  name: "TestAxios",
  data() {
    return {
      msg: ""
    };
  },
  methods: {
    doGetReq() {
      testGet({ name: "qw12w" })
        .then(res => {
          console.log(res);
          console.log(JSON.stringify(res));
          this.msg = JSON.stringify(res);
        })
        .catch(err => {
          console.log(err);
        });

      // // proxy代理 此处/rest 相当于http://localhost:8080
      // // proxy代理配置 见vue.config.js
      // let url = '/rest/getUserByName?name=qw12w';
      // reqGlobal.get(url).then(res => {
      //     console.log(res)
      //     console.log(JSON.stringify(res))
      //     this.msg = JSON.stringify(res);
      // }).catch(err => {
      //     console.log(err)
      // });
    },

    doPostReq() {}
  },
  created() {
    console.log("测试Mock接口的返回结果");
    testMockApi()
      .then(res => {
        console.log(res);
        console.log(JSON.stringify(res));
      })
      .catch(err => {
        console.log(err);
      });
    // axios.get("/goods/list").then(res => {
    //   console.log(res);
    // });
  }
};
</script>

<style scoped>
</style>
